<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Manager
 *
 * @author admin
 */
class Manager {

function __construct() {
$db = mysql_connect("localhost", "root", "root");
mysql_selectdb("projet2", $db);
}

public function AfficherListeServices() {



$login = $_SESSION['login'];
echo '<table border="1"><caption>LISTE DES SERVICES</caption> <th>nom service</th> <th>consulter taches service</th>';
$sql = mysql_query("select login,motdepasse,nom,prenom,nomservice from manager,services where (login='$login' and manager.idservice=services.id )");

while ($row = mysql_fetch_array($sql)) {
$var = $row['nomservice'];
echo "<tr><td>".$row['nomservice'] . "</td><td>" . "<a href='tachesmanager.php?login2=$login&serv=$var'> consulter taches de ce service</a> </td></tr>";
}
echo '</table>';
}

public function ListeTaches() {

if (isset($_GET['login2']) && isset($_GET['serv'])) {
$login3 = $_GET['login2'];

$service = $_GET['serv'];

$sal01 = mysql_query("update test set login='$login3' where nom='login'");
$sql0 = mysql_query("update test set nomservice='$service' where nom='test'");

echo '<table border="1"><caption>LISTE DES TACHES</caption>  <th>nom tache</th> <th>login collaborateur</th> <th>pourcentage</th> <th>date cloture</th> <th>etat</th> <th>date de début</th> <th>charge</th> <th>commentaire</th> <th>suppression</th ><th>modification</th> <th>cloture</th>';
// $sql = mysql_query("select nomtache,logincollaborateur,pourcentage,etat,datecloture from services s,tache t where (t.idservice = s.id and s.loginmanager = '$login3' and nomservice='$service' )");
$sql = mysql_query("select distinct nomtache,pourcentage,datecloture,logincollaborateur,etat,c.email,datedebut,charge,commentaire from tache t , manager m ,collaborateur c where (m.login='$login3' and t.service='$service' ) group by nomtache");
while ($row = mysql_fetch_array($sql)) {
$nom = $row['nomtache'];
$mailcol = $row['email'];
echo "<tr><td>".$row['nomtache'] . "</td><td>" . $row['logincollaborateur'] . "</td><td>" . $row['pourcentage'] . "</td><td>" . $row['datecloture'] . "</td><td>" . $row['etat'] ."</td><td>".$row['datedebut']."</td><td>".$row['charge']."</td><td>".$row['commentaire']. "</td><td> <a href='supprimertache.php?nomtache=$nom'>supprimer</a> </td><td> <a href='modifiertache.php?nomtache=$nom&emailcol=$mailcol'>modifier</a> </td><td> <a href='cloturertache.php?nomtache=$nom'>cloturer</a> </td></tr>";
}
}
echo '</table>';
}

public function AjouterTache() {



if (isset($_POST['nomtache']) && isset($_POST['pourcentagetache']) && isset($_POST['listcol']) && isset($_POST['datecloturetache'])) {

$nom = $_POST['nomtache'];
$pourcentage = $_POST['pourcentagetache'];
$date = $_POST['datecloturetache'];
$listecol = $_POST['listcol'];
$service4 = mysql_query("select  nomservice from test where nom='test'");
$tab = mysql_fetch_array($service4);
$a = $tab['nomservice'];


$sql = mysql_query("insert into tache (nomtache,pourcentage,datecloture,logincollaborateur,etat,service) values ('$nom','$pourcentage','$date','$listecol','en attente','$a')");
$sql1 = mysql_query("select email from collaborateur where login='$listecol'");
$row = mysql_fetch_array($sql1);
$mailcol = $row['email'];
$sql2 = mysql_query("select login from test where nom='login'");
$row2 = mysql_fetch_array($sql2);
$aa = $row2['login'];
$sql00 = mysql_query("update tache set loginmanager='$aa' where nomtache='$nom'");
$sql3 = mysql_query("select email from manager where login='$aa' ");
$row3 = mysql_fetch_array($sql3);
$mailman = $row3['email'];
ini_set("display_errors",0);error_reporting(0);
ini_set("SMTP", "smtp.topnet.tn");
$message = "le nom de  la tache est :".$nom."|  le pourcentage est :".$pourcentage."   |  la date de cloture est :".$date."";

$to = $mailcol."";
$subject = "une tache vous aiez attribué";

$from = $mailman."";
$headers = "From:" . $from;

    
if (mail($to, $subject, $message, $headers)) {
echo "<script language='javascript'>alert('le collaborateur a été informé'); </script>";
} else {
echo "<script language='javascript'>alert('mail non  envoyé'); </script>";
}

 
    



if ($sql) {
echo "<script language='javascript'>alert('ajouté avec success'); </script>";
} else {
echo "<script language='javascript'>alert('echec d ajout'); </script>";
}
}
}

public function SupprimerTache() {

if (isset($_GET['nomtache'])) {
$nom = $_GET['nomtache'];
$sql = mysql_query("delete from tache where nomtache='$nom'");
if ($sql) {
echo "<script language='javascript'>alert('supprimé avec success'); </script>";
 
} else {
echo "<script language='javascript'>alert('suppression échoué'); </script>";
}
}
}

public function ClotureTache() {

if (isset($_GET['nomtache'])) {
$nom2 = $_GET['nomtache'];

$sql = mysql_query("update tache set etat='cloturé' where nomtache='$nom2'");
if ($sql) {
echo "<script language='javascript'>alert('tache cloturé !'); </script>";
} else {
echo "<script language='javascript'>alert('echec'); </script>";
}
}
}

public function ModifierTache() {

if (isset($_POST['nomtache2']) && isset($_POST['pourcentagetache2']) && isset($_POST['listcol2']) && isset($_POST['datecloturetache2']) && isset($_POST['etattache']) && isset($_GET['nomtache']) && isset($_GET['emailcol'])) {

$nom = $_POST['nomtache2'];
$pourcentage = $_POST['pourcentagetache2'];
$date = $_POST['datecloturetache2'];
$listecol = $_POST['listcol2'];
$etat = $_POST['etattache'];
$anciennom = $_GET['nomtache'];
$ancienmail = $_GET['emailcol'];
$area = $_POST['commentaire'];



$sql = mysql_query("update tache set nomtache='$nom',pourcentage='$pourcentage',datecloture='$date',logincollaborateur='$listecol',etat='$etat' where nomtache='$anciennom' ");
$sql1 = mysql_query("select distinct email from collaborateur where login='$listecol'");
$row = mysql_fetch_array($sql1);
$b = $row['email'];
$sql2 = mysql_query("select login from test where nom='login'");
$row2 = mysql_fetch_array($sql2);
$c = $row2['login'];
$sql3 = mysql_query("select email from manager where login='$c'");
$row3 = mysql_fetch_array($sql3);
$d = $row3['email'];

ini_set("display_errors",0);error_reporting(0);
ini_set("SMTP", "smtp.topnet.tn");
$message = "il y a  eu un changement au niveau des  taches , veuillez consulter vos données : 
                   avec ce commentaire :".$area."";
$message2 = "il y a  eu un changement au niveau des  taches , veuillez consulter vos données ";


$to = $b."";
$subject = "modification de  taches";

$from = $d."";
$headers = "From:" . $from;
if (mail($to, $subject, $message, $headers)) {
echo "<script language='javascript'>alert('le destinataire a été informé de la modification'); </script>";
} else {
echo "<script language='javascript'>alert('mail non envoyé'); </script>";
}
//ini_set("SMTP","smtp.topnet.tn");
$to2 = $ancienmail."";
$subject2 = "modification de  taches";

$from2 = $d."";
$headers2 = "From:" . $from2;
if (mail($to2, $subject2, $message2, $headers2)) {
echo "<script language='javascript'>alert('l ancien collaborateur de cette tache a été informé de la modification'); </script>";
} else {
echo "<script language='javascript'>alert('mail non envoyé'); </script>";
}

if ($sql && $sql1) {
echo "<script language='javascript'>alert('modification avec success'); </script>";
} else {
echo "<script language='javascript'>alert('modification échoué'); </script>";
}
}
}
public function PassageTache() {
    if (isset($_GET['nomtache'])){
        
        $nomtache = $_GET['nomtache'];
        mysql_query("update modification set tache='$nomtache' where id='tache' ");
    }
    
}
}
?>
